<template>
  <div class="app-container">


    <el-table :data="data" >
      <el-table-column type="expand" prop="dataList" >
        <template slot-scope="scope1">
          <el-table :data="scope1.row.postList" size="mini">
            <el-table-column label="职位" prop="dictLable" >
              <template slot-scope="scope">
                <span>{{scope.row.postName}}({{scope.row.postCode}})</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" >
              <template slot-scope="scope">
                <el-button type="primary" @click="clickCode(scope1.row.deptId,scope.row.postId, scope.row.postCode)">生成考核码</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>

      <el-table-column label="公司名称" prop="deptName">

      </el-table-column>


    </el-table>

<!--    <el-table  :data="data" >-->


<!--      <el-table-column  align="left" prop="deptName" >-->

<!--      </el-table-column>-->

<!--    </el-table>-->

  </div>
</template>

<script>
import { getDeptCodeList, genCode} from "@/api/kh/code";

export default {
  name: "Code",
  data() {
    return {
      //返回数据
      data:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 考核码表格数据
      codeList: [],
      //考核计划 id
      assessmentId: undefined,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        assessmentCode: undefined,
        userId: undefined,
        level: undefined,
        assessmentId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.form.assessmentId = this.$route.params && this.$route.params.assessmentId;
    this.getDeptCodeList1();
  },
  methods: {
    // 根据考核计划id 可生成考核码 公司列表
    getDeptCodeList1(){
      getDeptCodeList(this.form.assessmentId).then(response =>{
        this.data=response.data;
      })
    },
    //点击生成考核码
    clickCode(deptId, postId, postCode){
      var that = this;
      this.form.deptId=parseInt(deptId);
      this.form.postId= postId;
      this.form.postCode=postCode;
      //获取 考核计划id  路由获取
        if(postCode=='C' | postCode == 'C1' | postCode == 'D1'){
            this.$prompt('请输入生成的数量','提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              inputPattern: /^[1-9]\d{0,3}$/,
              inputErrorMessage: '只能输入数字'
            }).then(({value})=>{
              this.form.codeNumber=value;
              genCode(this.form).then(response=>{
                  if(response.code===200){
                    this.msgSuccess(response.msg);
                  }else {
                    this.msgError(response.msg);
                  }
              })
            })
        }else {
          genCode(this.form).then(response=>{
            if(response.code===200){
              this.msgSuccess(response.msg);
            }else {
              this.msgError(response.msg);
            }
          })
        }
    }

  }
};
</script>
